#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2021-7-19 22:17
"""
写入文件
"""
filename = 'programming.txt'
# 写入空数据
with open(filename, 'w') as f:
    num = 1
    str_content = "I love programming."
    f.write(f'{str(num)}\n')
    f.write(f'{str_content}\n')

# 向文件中添加内容，不覆盖原有的内容
with open(filename, 'a', encoding='utf-8') as f:
    f.write('添加附加内容！\n')
    f.write('只能成功，不能失败！\n')

# 练习10-3【访客】
your_name = input('请输入您的姓名：')
with open(filename, 'a', encoding='utf-8') as f:
    f.write(f'{your_name}\n')

# 练习10-4【访客名单】
while True:
    your_name = input("请输入访客姓名，输入quit退出：")
    if your_name == 'quit':
        break
    else:
        with open(filename, 'a', encoding='utf-8') as f:
            f.write(f'{your_name}\n')

#练习10-5【调查】
while True:
    your_name = input("请输入喜欢的原因，输入quit退出：")
    if your_name == 'quit':
        break
    else:
        with open(filename, 'a', encoding='utf-8') as f:
            f.write(f'{your_name}\n')